package com.emcom.gotour.mvc.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.emcom.gotour.enums.TourType;
import com.emcom.gotour.mvc.message.TypeViewMessage;
import com.emcom.gotour.mvc.view.MenuView;
import com.emcom.gotour.mvc.view.TypeView;
import com.emcom.gotour.po.TourContent;
import com.emcom.gotour.service.TourContentService;
import com.emcom.gotour.vo.ChatVO;

@Controller
public class TypeController {

	@Autowired
	private TourContentService tourContentService;

	@Autowired
	private MessageSource messageSource;

	@Autowired
	private ChatVO chat;

	@RequestMapping(value={"/type.html"})
	public void type(HttpServletRequest request) {
		String tourType = request.getParameter("tourType");
		Map<String, List<TourContent>> categoryMap = new HashMap<String, List<TourContent>>();
		List<String> categoryList = tourContentService.queryCategory(TourType.valueOf(tourType));
		for(String category : categoryList) {
			List<TourContent> tourList = tourContentService.queryCategoryContent(category);
			categoryMap.put(category, tourList);
		}
		List<TourContent> popularList = tourContentService.queryPopularContent();
		TourContent ad = tourContentService.queryAd();
		TypeView view = new TypeView();
		view.setTitle(TypeViewMessage.Title.value(request, messageSource));
		view.setTourType(tourType);
		view.setCategoryMap(categoryMap);
		view.setPopularList(popularList);
		view.setAd(ad);
		view.setMenuView(new MenuView(request, messageSource));
		request.setAttribute("view", view);
		request.setAttribute("chat", chat);
	}

}
